<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- 2、// 编写一个函数，实现输入任意一个JSON对象，返回这个对象中所有 Number 类型值之和
function getSum(){
//你的实现
}

const jsonObj = {
    a: 1,
    b: {
        c: 2,
        d: "abc",
        e: [1,2]
    },
    e: {
        f: {
            g: 3
        }
    }
}

getSum(jsonObj);
// 返回结果 9 -->

<body>
    <div>test15-2</div>
    <script>
        const jsonObj = {
            a: 1,
            b: {
                c: 2,
                d: "abc",
                e: [1, 2]
            },
            e: {
                f: {
                    g: 3
                }
            }
        }
        let arr = []
        function getSum(obj) {
           for (const key in obj) {
              if(typeof(obj[key])==="number"){
                  arr.push(obj[key])
              }
              if(typeof(obj[key])==="object"){
                getSum(obj[key])
              }
           }
           return arr.reduce((pre,cur)=>pre+cur)
        }
        console.log(getSum(jsonObj));
    </script>
</body>

</html>